<?php
/**
 * 
 * @author John Cox
 * @access public 
 */
function reequipment_schedulerapi_sendmailparts()
{
    // The user API function is called
    $users = xarModAPIFunc('reequipment', 'user', 'getrel');
    // return var_export($users);
    // Check each user to see if there is overdue maintenance.  If so, send an email.
    for ($i = 0; $i < count($users); $i++) {
        $user = $users[$i];
        // First check to see if there is overdue maintenance
        $data['overdue_parts'] = xarModAPIFunc('reequipment', 'user', 'getorders', array('over_due' => true, 'company_id' => $company_id));
        
        // If there is nothing overdue, just return.
        if (empty($data['overdue_parts'])){
            return true;
        }
        
        // Create the message
        $htmlmessage = '<h4>Your Expected Parts Have Not Arrived.</h4>';
		$htmlmessage .= '<p>Check in at <a href="http://www.re-tread.org"> Re-</a> to see what is waiting.<p>';
		
		$message = 'You have overdue parts waiting at http://www.re-tread.org .';
        
        // If we made it this far, get the email address and names in this company.
        // Get user information
        $data = xarModAPIFunc('roles', 'user', 'get', array('uid' => $user['user_id']));
        
        // If we don't recognize the person, return.
        if ($data == false) return;

        // Send the mail for this person.
        if (!xarModAPIFunc('mail', 'admin', 'sendhtmlmail',array('info'     => $data['email'],
                                                                                        'name'     => $data['name'],
                                                                                        'subject'  => 'Re- Overdue Parts',
                                                                                        'bccinfo' => 'john.cox@re-heat.org',
                                                                                        'bccname' => 'John Cox',
                                                                                        'message'  => $message,
                                                                                        'htmlmessage' => $htmlmessage))) return;
    }
    return true;
}
?>